-
-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(Hopefully) fix the MQTT disconnections happening all the time #682
Conversation
…ime on some devices (e.g., when there is lots of busy traffic on BSB)
I am testing this PR in production. No disconnects seen yet, although temperature in my house is raising due to heavy heater activity. |
But that's how it's defined in PubSubClient.h (15 seconds default). |
If there is a newer version of PubSubClient, I rather update to the full new version rather than patching bits and pieces of the code, but thanks for the pointer, and I'm glad if this will fix the problem. |
Unfortunately theres no newer version. The maintainer has told us that he won't take care of the client anymore, except very important (security) bugs: knolleary/pubsubclient#1045 |
Give it a few days and I will proceed with testing. So far all looks fine. I will give you a ping, if this solves the issue completely or at least lets the problem appear more seldom. |
Yes I know, but that was already criticied in the issues of this project. Basically this low socket timeout makes it incompatible to the defaults as used in mosquitto (there it uses 60s to send pings to keep connection alive). Of course you could lower that value in mosquittos config, but the better fix is to let the client wait longer for pings. |
Ok, understood, thanks! |
It looks like somebody else took maintenance of the pubsubclient: https://github.com/thingsboard/pubsubclient. More details also here: https://registry.platformio.org/libraries/thingsboard/TBPubSubClient Unfortunately this code still has the problem with the lost pings, so the bugfix presented here is still missing. But they fixed security issues. Unfortunately I had one more short disconnection a few minutes ago. But not as many as before. I will try to update to the latest version of the above fork and give it a try, possibly later or over night. |
…v/fix_mqtt_disconnects
I merged with main branch. |
I am closing this because I made the update to 2.10 provided by https://github.com/thingsboard/pubsubclient See separate PR. |
This PR adds better values for keep alives and socket timeouts:
The keep alive tells the client to send a packet to the broker to tell it "yes I am there". If the broker does not get keep alive packets often enough, it will disconnect.
Actually the socket timeout identical to keep alive looks strange to me. I raised it to 120 seconds. This would mean that if the server does not send a keep alive to the client in time, the client will kill the connection. The default keep alive value in Mosquitto is 60 secs, minimum configurable is 5s:
MAN page of mosquitto:
Basically the socket timeout needs
>>
keep-alives (thats what my knowledge about similar protocols tell me, I am devloping large network protocols with Elasticsearch/Apache Lucene/Apache Solr so that's my daily business).It also looks like one of the many keepalive bugs in the (now unmaintained) PubSubClient:
Those issues seem to be fixed by: knolleary/pubsubclient#802
As you have the code of PubSubClient 2.8 included, I also added the missing line in it.
To explain why it happens:
The fix is to initialize
pingOutstanding=false
on connection.